package com.example.computer_exam_training_sys.controller;

import com.example.computer_exam_training_sys.dto.LearningGoalDTO;
import com.example.computer_exam_training_sys.service.UserLearningGoalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/api/goals")
public class UserLearningGoalController {

    @Autowired
    private UserLearningGoalService goalService;

    @GetMapping("/user/{userId}")
    public ResponseEntity<List<LearningGoalDTO>> getUserGoals(@PathVariable Long userId) {
        List<LearningGoalDTO> goals = goalService.getUserGoals(userId);
        return ResponseEntity.ok(goals);
    }

    @PostMapping("/settinggoal")
    public ResponseEntity<LearningGoalDTO> createGoal(
            @RequestParam Long userId,
            @RequestParam String goalType,
            @RequestParam Integer targetValue,
            @RequestParam String startDate,
            @RequestParam String endDate) {
        LearningGoalDTO goal = goalService.createGoal(userId, goalType, targetValue, startDate, endDate);
        return ResponseEntity.ok(goal);

    }

    @PutMapping("/{goalId}/progress")
    public ResponseEntity<LearningGoalDTO> updateGoalProgress(
            @PathVariable Long goalId,
            @RequestParam Integer currentValue) {
        LearningGoalDTO goal = goalService.updateGoalProgress(goalId, currentValue);
        return ResponseEntity.ok(goal);
    }

    @GetMapping("/user/{userId}/completion")
    public ResponseEntity<List<LearningGoalDTO>> getGoalCompletionStatus(@PathVariable Long userId) {
        List<LearningGoalDTO> goals = goalService.getGoalCompletionStatus(userId);
        return ResponseEntity.ok(goals);
    }

    @GetMapping("/user/{userId}/suggestions")
    public ResponseEntity<List<LearningGoalDTO>> getGoalSuggestions(@PathVariable Long userId) {
        List<LearningGoalDTO> suggestions = goalService.getGoalSuggestions(userId);
        return ResponseEntity.ok(suggestions);
    }
}
